<template>
  <div>
    <!-- 面包屑导航区域 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片区域 -->
    <el-card>
      <div id="main" style="width: 1200px; height: 555px"></div>
    </el-card>
  </div>
</template>

<script>
//导入echarts
import * as echarts from 'echarts';
/* //按需导入图表类型
import { LineChart } from 'echarts/charts';
//引入提示框，标题，直角坐标系组件，组件后缀都为 Component
import {
  TitleComponent,
  TooltipComponent,
  GridComponent,
} from 'echarts/components';
// 引入 Canvas 渲染器，注意引入 CanvasRenderer 或者 SVGRenderer 是必须的一步
import { CanvasRenderer } from 'echarts/renderers';
// 注册必须的组件
echarts.use([
  TitleComponent,
  TooltipComponent,
  GridComponent,
  LineChart,
  CanvasRenderer,
]); */
//导入lodash合并请求的配置项
import _ from 'lodash';

export default {
  data() {
    return {
      //需要合并的数据
      options: {
        title: {
          text: '用户来源',
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3',
            },
          },
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true,
        },
        xAxis: [
          {
            boundaryGap: false,
          },
        ],
        yAxis: [
          {
            type: 'value',
          },
        ],
      },
    };
  },
  created() {},
  //页面元素渲染完毕执行
  async mounted() {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('main'));
    //请求表数据
    const { data: response } = await this.$http.get('reports/type/1');
    if (response.meta.status !== 200)
      return this.$message({
        message: response.meta.msg,
        type: 'error',
        center: true,
      });
    //把请求的数据和样式数据合并
    const result = _.merge(response.data, this.options);
    // 绘制图表
    myChart.setOption(result);
    window.addEventListener('resize', () => myChart.resize());
  },
  methods: {},
};
</script>

<style scoped>
</style>